*********************************************************************
*** Political costs of trade war tariffs 
*** Edward D. Mansfield & Omer Solodoch 
*** Replication code for analysis of the Gallup poll  
*** Note: replicators must install the following packages from the SSC Archive:
*** ssc install ebalance
*** ssc install outtable
*** ssc install coefplot
*** ssc install esttab
*********************************************************************

*********************************************************************
clear all
version 17
*** Set working directory
capture cd "XXXX"
*** Load dataset
use "MSJOP_Gallup.dta", clear
*********************************************************************


************************************************************
*** Table 3: post-escalation effect on voting preferences
************************************************************
logit wont_vote   TRUMPAPP1 vote_GOP vote_Dem post_escalation  pid3 i.income7 collegegrad i.gr i.age3 i.race_eth i.phonestatus calls4 i.ZIPSTATE  if party<=5
gen logitsamp = e(sample)

estimates clear
foreach var in TRUMPAPP1 vote_GOP vote_Dem wont_vote {
	eststo: logit `var' post_escalation  tariff_exposure pid3 i.income7  collegegrad i.gr i.age3 i.race_eth i.phonestatus calls4 i.ZIPSTATE  if logitsamp==1 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
}

** export table
 esttab est1 est2 est3 est4, keep(post_escalation tariff_exposure) ///
order(post_escalation tariff_exposure) ///
 se(3) b(3) replace star(* 0.05 ** 0.01) label  nonotes nogaps  ///
 s(controls sfixedef N r2_p, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "Pseudo R-squared"))

**** effect size (percentage points)
qui logit vote_GOP i.post_escalation  tariff_exposure pid3 i.income7  collegegrad i.gr i.age3 i.race_eth i.phonestatus calls4 i.ZIPSTATE  if logitsamp==1 
margins, dydx(post_escalation) atmeans

************************************************************
*** Tables A-13 & A-14: balance and the effect of post-escalation using entropy balancing
************************************************************
ebalance post_escalation  ///
 agec2 agec3 female race2 race3 race4 education2 collegegrad incomec2 incomec3 incomec4 incomec5 incomec6 emp_chn_target_cum_june pid3  if logitsamp==1, targets(2)

***with labels:
matrix A = e(preBal)
matrix B = e(postBal)
 esttab mat(A, fmt(%9.3fc)), label compress 
 esttab mat(B, fmt(%9.3fc)), label compress  

estimates clear
foreach var in TRUMPAPP1 vote_GOP vote_Dem wont_vote {
	eststo: areg `var' post_escalation agec2 agec3 female race2 race3 race4 education2 collegegrad incomec2 incomec3 incomec4 incomec5 incomec6 emp_chn_target_cum_june pid3 [aweight=_webal] if logitsamp==1, absorb(ZIPSTATE) robust 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
}

** export table
 esttab est1 est2 est3 est4, keep(post_escalation) ///
order(post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 s(controls sfixedef N r2, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "R-squared"))


************************************************************
*** Table A-15: post-escalation effect on voting preferences, without controlling for party id
************************************************************

estimates clear
foreach var in TRUMPAPP1 vote_GOP vote_Dem wont_vote {
	eststo: logit `var' post_escalation  tariff_exposure  i.income7  collegegrad i.gr i.age3 i.race_eth i.phonestatus calls4 i.ZIPSTATE  if logitsamp==1 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
}

** export table
 esttab est1 est2 est3 est4, keep(post_escalation tariff_exposure) ///
order(post_escalation tariff_exposure) ///
 se(3) b(3) replace star(* 0.05 ** 0.01) label  nonotes nogaps  ///
 s(controls sfixedef N r2_p, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "Pseudo R-squared"))

*************************************************************************************************************
*** Table A-16: post-escalation effect, without controlling for demographic and socioeconomic characteristics
*** or respondents' reachability (call attempts and phone status)
*************************************************************************************************************
estimates clear
foreach var in TRUMPAPP1 vote_GOP vote_Dem wont_vote {
	eststo: logit `var' post_escalation i.ZIPSTATE if logitsamp==1 
estadd local sfixedef "\checkmark", replace
}

** export table
 esttab est1 est2 est3 est4, keep(post_escalation) ///
order(post_escalation) ///
 se(3) b(3) replace star(* 0.05 ** 0.01) label nonotes nogaps  ///
 s(sfixedef N r2_p, fmt(0 0 3) label("State FE" "Observations" "Pseudo R-squared"))


*********************************************************************************